package com.student.util;

import java.io.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

public class UploadFile {

	public static void uploadFile(String stu_no,HttpServletRequest request) throws Exception
	{
		MultipartHttpServletRequest  multipartRequest  =  (MultipartHttpServletRequest)request;   
		CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("path");       
		// 创建文件    
		ServletContext context = request.getSession().getServletContext();
		File dirPath = new File(context.getRealPath("/")+"upload/student");   
		if (!dirPath.exists()) {    
			dirPath.mkdir();    
		}    
		File uploadFile = new File(dirPath+"/"+stu_no);   
		FileCopyUtils.copy(file.getBytes(), uploadFile);
	}
}
